# include <bits/stdc++.h>
# define MAXN 1027
using namespace std;

int bit[MAXN][MAXN], n, op;

inline int lb(int x) {return x & -x;}

inline void add2(int *s, int x, int p) { 
    for(; x <= n; x += lb(x)) s[x] += p;
}

inline void add1(int x, int y, int p) { 
    for(; x <= n; x += lb(x)) add2(bit[x], y, p);
}

inline int query2(int *s, int x) { 
    int tmp = 0;
    for(; x; x -= lb(x)) tmp += s[x];
    return tmp;
}

inline int query1(int x, int y) { 
    int tmp = 0;
    for(; x; x -= lb(x)) tmp += query2(bit[x], y);
    return tmp;
}

int main() { 
# ifndef LOCAL 
    freopen("mobilephones.in", "r", stdin);
    freopen("mobilephones.out", "w", stdout);
# endif
    scanf("%d %d", &op, &n);
    while(true) { 
        scanf("%d", &op);
        if(op == 3) return 0;
        else if(op == 1) { 
            int x, y, p;
            scanf("%d %d %d", &x, &y, &p);
            add1(++x, ++y, p);
        } else if(op == 2) { 
            int l, b, r, t;
            scanf("%d %d %d %d", &l, &b, &r, &t);
            l++, b++, r++, t++;
            printf("%d\n", query1(r, t) + query1(l - 1, b - 1) - query1(l - 1, t) - query1(r, b - 1));
        }
    }
}
